export default function request(option) {
	const Authorization = uni.getStorageSync("token")
	const BaseUrl = getApp().globalData.baseURL;
	return new Promise((resolve, reject) => {
		uni.request({
			url: BaseUrl + option.url,
			method: option.method || "get",
			header: {
				Authorization,
				...option.header
			},
			params: option.params || {},
			data: option.data || {},
			success: (result) => {
				if (result.data.code === 401) {
					uni.clearStorage();
					uni.showToast({
						title: '您的登陆状态已过期，请重新登录',
						icon: "none"
					})
					uni.reLaunch({
						url: '/pages/user/login'
					})
					return;
				} else if (result.statusCode < 305) {
					resolve(result.data);
				} else {
					reject(result);
				}
			},
			fail: reject
		})
	})
	// .catch(() => {
	// 	uni.showToast({
	// 		title:'服务器出错',
	// 		icon:"error"
	// 	})
	// })
}